let selectTimeEl = document.querySelector('.selectTime')
let selectConditionEl = document.querySelector('.selectCondition')

let selectTimeEle = document.querySelector('#selectTime')
let selectConditionEle = document.querySelector('#selectCondition')

let maskEl = document.querySelector('.mask')

let isTimeDisplay = false;
let isConDisplay = false;

let timeBox = document.querySelector('.timeBox')
let conditionBox = document.querySelector('.conditionBox')

//获取搜索框元素
let searchEl = document.querySelector('#search')


//获取页面上的账单数据
let pageResult = null

//获取开始日期与结束日期元素
let startTime = document.querySelector('.startTime')
let endTime = document.querySelector('.endTime')

//日历盒子
let calendarBox = document.querySelector('.calendarBox')

//显示每个月天数的区域
let calendarEl = document.querySelector('.calendar')

//选中某一天显示的具体日期（默认为当前日期）
let exactYearEl = document.querySelector('.exactYear')
let exactMonthEl = document.querySelector('.exactMonth')
let exactDayEl = document.querySelector('.exactDay')

//页面可选择的年月
let yearEl = document.querySelector('.year')
let monthEl = document.querySelector('.month')

//账单时间
let billItemList = document.querySelectorAll('.bill ul li')
// 本月 上月 今年 去年 2022-2023 全部
let thisMonth = document.querySelector('#thisMonth')
let lastMonth = document.querySelector('#lastMonth')
let thisYear = document.querySelector('#thisYear')
let lastYear = document.querySelector('#lastYear')
let range = document.querySelector('#range')
let all = document.querySelector('#all')


//分组方式
let groupItemList = document.querySelectorAll('.group ul li')
let noGroupEl = document.querySelector('#noGroup')
let groupByDayEl = document.querySelector('#groupByDay')
let groupByMonthEl = document.querySelector('#groupByMonth')


//账单类型
let kindItemList = document.querySelectorAll('.kind ul li')


//选择账单时间
for (let i = 0; i < billItemList.length; i++) {
    billItemList[i].dataset.index = 0
    billItemList[i].onclick = function () {
        if (!this.textContent) return;
        remove(billItemList)
        billItemList[i].classList.add('active')
        selectTimeEle.textContent = billItemList[i].textContent
        selectTime()
    }
}

//dataset-index字段表示分组方式，0 不分组  1 按天分  2 按月分
startTime.dataset.index = 0
endTime.dataset.index = 0

//选择分组方式
for (let i = 0; i < groupItemList.length; i++) {
    groupItemList[i].dataset.index = i
    groupItemList[i].onclick = function () {
        if (!this.textContent) return;
        remove(groupItemList)
        groupItemList[i].classList.add('active')
        selectTime()
    }
}

//选择账单类型
let types = ['all', 'outcome', 'income', 'reimburse']
let typeOfMoney = 'all'
for (let i = 0; i < kindItemList.length; i++) {
    kindItemList[i].dataset.type = types[i]
    kindItemList[i].dataset.index = 0
    kindItemList[i].onclick = function () {
        if (!this.textContent) return;
        remove(kindItemList)
        kindItemList[i].classList.add('active')

        typeOfMoney = kindItemList[i].dataset.type
        console.log('typeOfMoney',typeOfMoney)
    }
}

//-----------------------------------------------------


//获取当前时间的年月日
let date = new Date();
let year = date.getFullYear(); //年
let month = date.getMonth(); //月


let now = date
let nowYear = now.getFullYear(); //年
let nowMonth = date.getMonth() + 1
let nowDay = now.getDate() //日

if (nowMonth > 12) {
    nowYear += 1
    nowMonth = 1
} else if (nowMonth < 0) {
    nowYear -= 1
    nowMonth = 12
}


date.setDate(1); // 将时间对象设置为本月的一号
let week = date.getDay(); // 获取本月的一号是周几

date.setMonth(month + 1);
date.setDate(0) // 将时间对象设置为上一个月的最后一天
let lastDateNumber = date.getDate();

let dateItemList = null

//-----------------------------------------------------

//切换年份的下拉框
let selectYearBtn = document.querySelector('#down')

//返回主页按钮
let returnBtn = document.querySelector('#return')

//切换上下月份的按钮
let prevBtn = document.querySelector('.prev')
let nextBtn = document.querySelector('.next')

//确定取消按钮
let cancelBtn = document.querySelector('.cancel')
let sureBtn = document.querySelector('.sure')

//用于确认时间范围的按钮
let okBtn = document.querySelector('.ok')

let target = null

//筛选面板上金额范围中的最大最小值
let min = document.querySelector('#min')
let max = document.querySelector('#max')

//筛选面板上的确定、重置按钮
let confirmBtn = document.querySelector('.confirm')
let resetBtn = document.querySelector('.reset')

exactYearEl.textContent = `${nowYear}`
exactMonthEl.textContent = `${nowMonth}`
exactDayEl.textContent = `${nowDay}`

yearEl.textContent = `${nowYear}`
monthEl.textContent = `${nowMonth}`

min.dataset.index = 0
max.dataset.index = 0
searchEl.dataset.index = 0

//渲染日期元素
setDateBox()
// 选择日历面板上的年份
setYearSelect()

let timer = setTimeout(function () {
    dateItemList = calendarEl.querySelectorAll('.item');

    renderDate(week, lastDateNumber);
    for (let i = 0; i < dateItemList.length; i++) {
        if (dateItemList[i].textContent == nowDay) {
            dateItemList[i].classList.add('active')
        }
    }

    // 为日期格子绑定事件
    for (let i = 0; i < dateItemList.length; i++) {
        dateItemList[i].onclick = function () {
            if (!this.textContent) return;

            remove(dateItemList)

            let date = this.textContent;
            let year = yearEl.textContent;
            let month = monthEl.textContent;

            exactYearEl.textContent = `${year}`
            exactMonthEl.textContent = `${month}`
            exactDayEl.textContent = `${date}`
            dateItemList[i].classList.add('active')
        }
    }


}, 0)

//监听事件
selectTimeEl.addEventListener('click', selectTime)
selectConditionEl.addEventListener('click', selectCondition)

startTime.addEventListener('click', selectDate)
endTime.addEventListener('click', selectDate)

searchEl.addEventListener('input', search)

selectYearBtn.addEventListener('change', changeHandel)

cancelBtn.addEventListener('click', cancel)
sureBtn.addEventListener('click', sure)

confirmBtn.addEventListener('click', select)
resetBtn.addEventListener('click', reset)

thisMonth.addEventListener('click', renderMonthBills)
lastMonth.addEventListener('click', renderLastMonthBills)
thisYear.addEventListener('click', renderYearBills)
lastYear.addEventListener('click', renderLastYearBills)
range.addEventListener('click', renderRangeBills)
all.addEventListener('click', renderAllBills)

noGroupEl.addEventListener('click', renderYearBills)
groupByDayEl.addEventListener('click', renderYearBills)
groupByMonthEl.addEventListener('click', renderYearBills)

noGroupEl.addEventListener('click', changeStatus)
groupByDayEl.addEventListener('click', changeStatus)
groupByMonthEl.addEventListener('click', changeStatus)

returnBtn.addEventListener('click', returnPage)

function returnPage() {
    location.href = './userMmt.html'
}

//改变状态（分组方式）
function changeStatus(e) {
    let target = e.target
    if (target.dataset.index == '0') {
        change(0)
    } else if (target.dataset.index == '1') {
        change(1)
    } else {
        change(2)
    }
}

function change(str) {
    for (let i = 0; i < billItemList.length; i++) {
        billItemList[i].dataset.index = str
    }
    for (let i = 0; i < kindItemList.length; i++) {
        kindItemList[i].dataset.index = str
    }
    startTime.dataset.index = str
    endTime.dataset.index = str
    min.dataset.index = str
    max.dataset.index = str
    searchEl.dataset.index = str
}

//日期面板上的取消按钮
function cancel() {
    calendarBox.style.display = 'none'
    maskEl.style.top = `2.56rem`
    maskEl.style.zIndex = 0
    maskEl.style.display = 'block'
}

//日期面板上的确认按钮
function sure() {
    cancel()
    // console.log(target)
    if (target.classList.contains('startTime')) {
        startTime.textContent =
            `${exactYearEl.textContent}-${exactMonthEl.textContent}-${exactDayEl.textContent}`

        //获取开始日期的年月日
        let startYear = Number(exactYearEl.textContent)
        let startMonth = Number(exactMonthEl.textContent)
        let startDay = Number(exactDayEl.textContent)
        console.log(startYear, startMonth, startDay)

    } else {
        endTime.textContent =
            `${exactYearEl.textContent}-${exactMonthEl.textContent}-${exactDayEl.textContent}`

        //获取结束日期的年月日
        let endYear = Number(exactYearEl.textContent)
        let endMonth = Number(exactMonthEl.textContent)
        let endDay = Number(exactDayEl.textContent)



    }
    if (startTime.textContent.includes('-') && endTime.textContent.includes('-')) {
        okBtn.style.display = 'block'
    }
    let start = new Date(startTime.textContent).getTime()
    let end = new Date(endTime.textContent).getTime()

    //自定义日期起止时间不为空时显示的确认按钮
    okBtn.addEventListener('click', function ok() {
        if (start > end) {
            console.alert('日期格式错误')
        } else {
            selectTimeEle.textContent = okBtn.parentElement.previousElementSibling.textContent
            closeBox(timeBox)
            isTimeDisplay = false
            renderSelectRangeBills()
        }
    })

}

//模糊搜索函数
function search() {
    let index = searchEl.dataset.index
    if (!searchEl.value) {
        renderBills(pageResult)
    }
    let value = searchEl.value
    console.log('pageResult',pageResult)
    console.log('value',value)
    let result = searchByKey(pageResult, value)
    console.log('result', result)
    if (result.length == 0) {
        dis.innerHTML = `<span class="remind">暂无数据</span>`
    }
    renderBills(result)
}

//关闭面板
function closeBox(box) {
    box.style.display = 'none'
    maskEl.style.display = 'none'
}

function remove(list) {
    for (let i = 0; i < list.length; i++) {
        list[i].classList.remove('active')
    }
}

// 点击上一月
prevBtn.onclick = function () {
    remove(dateItemList)
    let month = Number(monthEl.textContent); // 获取月
    let year = Number(yearEl.textContent); // 获取年
    console.log(month, year)
    // 上一个月信息
    month--

    // 目前为 1 月，进入上一年 12 月
    if (month < 1) {
        year--;
        month = 12;
    }

    monthEl.textContent = month
    yearEl.textContent = year


    let info = calcInfo(year, month - 1)

    renderDate(info.week, info.lastDateNumber)
}

// 点击下一月
nextBtn.onclick = function () {
    remove(dateItemList)
    let month = Number(monthEl.textContent); // 获取月
    let year = Number(yearEl.textContent); // 获取年

    // 下一个月信息
    month++

    // 目前为 12 月，进入下一年一月
    if (month > 12) {
        year++;
        month = 1;
    }

    monthEl.textContent = month
    yearEl.textContent = year


    let info = calcInfo(year, month - 1)

    renderDate(info.week, info.lastDateNumber)
}

function changeHandel() {
    yearEl.textContent = selectYearBtn.value
    let month = monthEl.textContent;
    let year = yearEl.textContent;

    let info = calcInfo(year, month - 1);
    renderDate(info.week, info.lastDateNumber)
}

function calcInfo(year, month) {
    let time = new Date(year, month);
    let week = time.getDay();

    time.setMonth(Number(month) + 1);
    time.setDate(0);
    let lastDateNumber = time.getDate();

    return {
        week,
        lastDateNumber
    }
}

function renderDate(week, lastDateNumber) {

    for (const dateItem of dateItemList) {
        dateItem.textContent = ''
    }


    for (let i = 0; i < lastDateNumber; i++) {
        dateItemList[i + week].textContent = i + 1;
    }
}

function setYearSelect() {
    for (let i = -4; i < 4; i++) {
        let option = new Option(year + i, year + i)
        selectYearBtn.append(option)
    }
    yearEl.textContent = year;
}

//渲染日期元素
function setDateBox() {
    let html = '';
    for (let i = 0; i < 45; i++) {
        html += `<div class="item"></div>`
    }

    calendarEl.innerHTML = html
}
//时间面板
function selectTime() {
    conditionBox.style.display = 'none'
    isConDisplay = false;
    isTimeDisplay = !isTimeDisplay
    toggle(timeBox, isTimeDisplay)
    searchEl.value = null
}

//筛选面板
function selectCondition() {
    timeBox.style.display = 'none'
    isTimeDisplay = false
    isConDisplay = !isConDisplay
    toggle(conditionBox, isConDisplay)
    searchEl.value = null
}

//筛选面板上的确认按钮
function select() {
    conditionBox.style.display = 'none'
    isConDisplay = false;
    maskEl.style.display = 'none'

    let selectMoneyResult = moneyRange()
    let selectTypeResult = billType()

    console.log('查询条件', selectMoneyResult, selectTypeResult)
    //有一个条件的结果没有数据
    if (!selectMoneyResult || !selectTypeResult) {
        dis.innerHTML = `<span class="remind">暂无数据</span>`
        return
    }
    let publicResult = []
    for (let i = 0; i < selectMoneyResult.length; i++) {

        if (selectTypeResult.includes(selectMoneyResult[i])) {
            publicResult.push(selectMoneyResult[i])
        }
    }
    if (publicResult.length == 0) {
        dis.innerHTML = `<span class="remind">暂无数据</span>`
        return
    }
    let index = min.dataset.index
    if (index === '2') {
        // console.log('按月')
        renderBillsByMonth(publicResult)
    } else if(index === '1'){
        renderBillsByDay(publicResult)
    } else {
        renderBills(publicResult)
    }
}
//通过金额范围筛选账单
function moneyRange() {
    let selectMoneyResult = pageResult
    if (min.value && max.value) {

        console.log('最大最小', Number(min.value), max.value);
        selectMoneyResult = filterByMoney(selectMoneyResult, Number(min.value), Number(max.value))
    }
    return selectMoneyResult
}

//通过账单类型筛选账单
function billType() {
    let selectTypeResult = pageResult
    selectTypeResult = filterByType(selectTypeResult, typeOfMoney)
    return selectTypeResult
}


//筛选面板上的重置按钮
function reset() {
    closeBox(conditionBox)
    let index = min.dataset.index
    isConDisplay = false
    min.value = null
    max.value = null
    typeOfMoney = 'all'
    judge(index, pageResult)
    for (let i = 0; i < kindItemList.length; i++) {
        remove(kindItemList)
        kindItemList[0].classList.add('active')
    }
}


// 切换显示
function toggle(Box, flag) {
    // console.log(Box, flag)
    if (flag) {
        Box.style.display = 'block'
        maskEl.style.display = 'block'
    } else {
        Box.style.display = 'none'
        maskEl.style.display = 'none'
    }
}

//日期显示切换
function selectDate(e) {

    calendarBox.style.display = 'block'
    maskEl.style.top = 0
    maskEl.style.zIndex = 1
    maskEl.style.display = 'block'
    target = e.target
}

function addZero(m) {
    return m < 10 ? '0' + m : m
}

function format(timeStamp, flag = false) {
    //时间戳转化为具体日期
    let time = new Date(timeStamp);
    let y = time.getFullYear();
    let m = time.getMonth() + 1;
    let d = time.getDate();
    let h = time.getHours();
    let min = time.getMinutes();
    if (flag) {
        return addZero(h) + ':' + addZero(min);
    }
    // let s = time.getSeconds();
    return y + '-' + addZero(m) + '-' + addZero(d) + ' ' 
        + addZero(h) + ':' + addZero(min);
}
let dis = document.querySelector('.display')

//不分组的渲染方式
async function render(result) {
    // console.log('render', result)
    // dataGroup(result, 'day')

    let html = ''
    for (let i = 0; i < result.length; i++) {
        let {
            time,
            annotation,
            money,
            moneyType,
            reimbursement,
            consumeType
        } = result[i]
        let number = null
        if (!moneyType) {
            number = -money
        } else {
            number = `+${money}`
        }
        if (reimbursement) number = money //报销
        time = format(time)
        html += `<div class="all">
        <span>
            <span>${time}</span>
        </span>
        <div class="block">
            <div>
                <div>
                    <span class="moneyType">·</span>
                    <span id="type">${consumeType}</span>
                </div>
                <span id="con">${annotation}</span>
            </div>
            <span class="moneyType">${number}</span>
        </div>
    </div>`
    }
    dis.innerHTML = html
}

//按天分组的渲染方式
async function renderByDay(result) {
    let resDate = dataGroup(result, 'day')
    let dates = []
    let dateBills = []
    for (let i = 0; i < resDate.length; i++) {
        dates.push(resDate[i].date)
        dateBills.push(resDate[i].subList)
    }
    let html = ''
    for (let i = 0; i < dates.length; i++) {
        html += `<div class="all">
        <span>
            <span>${dates[i]}</span>
        </span>
        <div class="list"></div>
    </div>`
    }
    dis.innerHTML = html
    return dateBills
}

async function addBillsByDay(result) {
    let dateBills = await renderByDay(result)
    // console.log('dateBills' ,dateBills)
    let listsEl = document.querySelectorAll('.list')
    // console.log('listsEl[0]' ,listsEl[0])
    // console.log('listEl', listsEl)
    let blockList = null
    for (let i = 0; i < dateBills.length; i++) {
        let html = ''
        for (let j = 0; j < dateBills[i].length; j++) {

            let {
                time,
                annotation,
                money,
                moneyType,
                reimbursement,
                consumeType
            } = dateBills[i][j]
            let number = null
            if (!moneyType) {
                number = -money
            } else {
                number = `+${money}`
            }
            if (reimbursement) number = money //报销
            time = format(time, true)
            html += `<div class="block">
            <div>
                <div>
                    <span id="moneyType">·</span>
                    <span id="type">${consumeType}</span>
                </div>
                <span>
                <span id="con">${time}</span>
                <span id="con">${annotation}</span>
                </span>
            </div>
            <span id="moneyType">${number}</span>
            </div>`
            setTimeout(() => {
                blockList = listsEl[i].querySelectorAll('.block')
                // console.log('blockList',blockList)
                let {
                    moneyType,
                    reimbursement
                } = dateBills[i][j]
                let colorEls = blockList[j].querySelectorAll('#moneyType')
                // console.log('colorEls',colorEls)
                if (moneyType) {
                    colorEls[0].style.color = 'green'
                    colorEls[1].style.color = 'green'
                } else {
                    colorEls[0].style.color = 'red'
                    colorEls[1].style.color = 'red'
                }
                if (reimbursement) {
                    colorEls[0].style.color = 'blue'
                    colorEls[1].style.color = 'blue'
                }
            }, 0);
        }
        listsEl[i].innerHTML = html
    }
}

//按月分组的渲染方式
async function renderByMonth(result) {
    let resDate = dataGroup(result, 'month')
    let dates = []
    let dateBills = []
    for (let i = 0; i < resDate.length; i++) {
        dates.push(resDate[i].date)
        dateBills.push(resDate[i].subList)
    }

    let html = ''
    for (let i = 0; i < dates.length; i++) {
        html += `<div class="all">
        <span>
            <span>${dates[i]}</span>
        </span>
        <div class="list"></div>
    </div>`
    }
    dis.innerHTML = html
    return dateBills
}

async function addBillsByMonth(result) {
    let dateBills = await renderByMonth(result)

    let listsEl = document.querySelectorAll('.list')

    let blockList = null
    for (let i = 0; i < dateBills.length; i++) {
        let html = ''
        for (let j = 0; j < dateBills[i].length; j++) {

            let {
                time,
                annotation,
                money,
                moneyType,
                reimbursement,
                consumeType
            } = dateBills[i][j]
            let number = null
            if (!moneyType) {
                number = -money
            } else {
                number = `+${money}`
            }
            if (reimbursement) number = money //报销
            time = format(time)
            html += `<div class="block">
            <div>
                <div>
                    <span id="moneyType">·</span>
                    <span id="type">${consumeType}</span>
                </div>
                <span>
                    <span id="con">${time}</span>
                    <span id="con">${annotation}</span>
                </span>
            </div>
            <span id="moneyType">${number}</span>
            </div>`
            setTimeout(() => {
                blockList = listsEl[i].querySelectorAll('.block')
                let {
                    moneyType,
                    reimbursement
                } = dateBills[i][j]
                let colorEls = blockList[j].querySelectorAll('#moneyType')

                if (moneyType) {
                    colorEls[0].style.color = 'green'
                    colorEls[1].style.color = 'green'
                } else {
                    colorEls[0].style.color = 'red'
                    colorEls[1].style.color = 'red'
                }
                if (reimbursement) {
                    colorEls[0].style.color = 'blue'
                    colorEls[1].style.color = 'blue'
                }
            }, 0);
        }
        listsEl[i].innerHTML = html
    }
}

async function renderBillsByMonth(result) {
    await addBillsByMonth(result)
    console.log('渲染月')
    return result
}

async function renderBillsByDay(result) {
    await addBillsByDay(result)
    console.log('渲染天')
    return result
}

async function renderBills(result) {
    // console.log("renderBills", result);
    await render(result)

    let allList = document.querySelectorAll('.all')
    // console.log('allList',allList)

    for (let i = 0; i < result.length; i++) {
        let {
            moneyType,
            reimbursement
        } = result[i]
        let colorEls = allList[i].querySelectorAll('.moneyType')
        if (moneyType) {
            // let colorEls = allList[i].querySelectorAll('.moneyType') 
            colorEls[0].style.color = 'green'
            colorEls[1].style.color = 'green'
        }
        if (reimbursement) {
            colorEls[0].style.color = 'blue'
            colorEls[1].style.color = 'blue'
        }
    }
    // console.log(result)
    return result
}

//判断有无账单数据
async function isHasData(result) {
    // let result = await renderYearBills()
    if (result) {
        // console.log(result)
        return result
    }
    dis.innerHTML = `<span class="remind">暂无数据</span>`
    return
}

//获取全部的账单数据
async function renderAllBills(e) {
    let target = e.target
    let result = await getAllData()
    let index = target.dataset.index
    judge(index,result)
}

//获取去年的账单数据
async function renderLastYearBills(e) {
    let target = e.target
    let index = target.dataset.index
    let result = await getData(new Date().getFullYear() - 1)
    judge(index,result)
}

//获取今年的账单数据
async function renderYearBills(e) {
    let target = e.target
    // console.log('target',target)
    let index = target.dataset.index
    let result = await getData(new Date().getFullYear())
    judge(index,result)
}

//判断是哪种分组方式
async function judge(index,result){
    if (index === '2') {
        console.log('按月')
        pageResult = await renderBillsByMonth(result)
    } else if(index === '1'){
        console.log('按天')
        pageResult = await renderBillsByDay(result)
    } else {
        console.log('不分组')
        pageResult = await renderBills(result)
    }
    isHasData(pageResult)
}

//默认今年的数据不分组
async function renderThisYear() {
    let result = await getData(new Date().getFullYear())
    pageResult = await renderBills(result)
    isHasData(pageResult)
}

renderThisYear() 


//获取上月的账单数据
async function renderLastMonthBills(e) {
    let target = e.target
    let index = target.dataset.index
    let result = await getData(new Date().getFullYear(), new Date().getMonth())
    judge(index,result)
}

//获取本月的账单数据
async function renderMonthBills(e) {
    let target = e.target
    let index = target.dataset.index
    let result = await getData(new Date().getFullYear(), new Date().getMonth() + 1)
    judge(index,result)
}

//获取2022-2023
async function renderRangeBills(e) {
    let target = e.target
    let index = target.dataset.index
    let result1 = await getData(2022)
    let result2 = await getData(2023)
    let result = [...result2, ...result1]
    judge(index,result)
}

//获取自定义日期范围内的账单数据
async function renderSelectRangeBills(e) {
    let index = startTime.dataset.index
    let result = await getAllData()
    let newResult = []
    //获取一整天的时间戳
    let timeStamp = new Date('2023-3-22').getTime() - new Date('2023-3-21').getTime()

    if (!result) { //没有数据
        dis.innerHTML = `<span class="remind">暂无数据</span>`
        return
    }
    let start = new Date(startTime.textContent).getTime()
    let end = new Date(endTime.textContent).getTime() + timeStamp
    for (let i = 0; i < result.length; i++) {
        if (result[i].time >= start && result[i].time <= end) {
            newResult.push(result[i])
        }
    }

    if (newResult.length == 0) {
        dis.innerHTML = `<span class="remind">暂无数据</span>`
        return
    }
    // pageResult = await renderBills(newResult)
    judge(index,newResult)
    return pageResult
}

//筛选账单类型
function filterByType(data, type) {
    if (!type || (type !== "income" && type !== "outcome" && type !== "reimburse" && type !== "all")) return;
  
    let result = [];
    if (type === "income") {
      result = data.filter(item => item.moneyType === true);
    } else if (type === "outcome") {
      result = data.filter(item => item.moneyType === false && item.reimbursement === false);
    } else if (type === "reimburse") {
      result = data.filter(item => item.reimbursement === true);
    } else if (type === "all") {
      result = data;
    }
  
    return result;
  }
